package com.wanshu.util;

import com.alibaba.fastjson.JSON;
import com.wanshu.entity.vo.ResultVo;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.PrintWriter;

public class ResultUtil {
    private static final Integer SUCCESS_CODE=0;
    private static final Integer FAIL_CODE=500;
    private static Logger logger = Logger.getLogger(ResultUtil.class);



    public static String success(String msg,Object data){
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(SUCCESS_CODE);
        resultVo.setMsg(msg);
        resultVo.setData(data);
        String jsonString = JSON.toJSONString(resultVo);
        return  jsonString;

    }

    public static String successPage(String msg,Object data,Integer count){
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(SUCCESS_CODE);
        resultVo.setMsg(msg);
        resultVo.setData(data);
        resultVo.setCount(count);
        String jsonString = JSON.toJSONString(resultVo);
        return  jsonString;

    }

    public static String fail(String msg,Object data){
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(FAIL_CODE);
        resultVo.setMsg(msg);
        resultVo.setData(data);
        String jsonString = JSON.toJSONString(resultVo);
        return  jsonString;

    }

//    public static  void response(HttpServletResponse response,String object){
//        try {
//            PrintWriter writer = response.getWriter();
//            writer.write(object);
//            writer.flush();
//            writer.close();
//
//        } catch (IOException e) {
//            logger.error("响应失败",e);
//        }
//    }


}
